﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AJWPFAdmin.Core.Components.AJTable.ViewModels
{
    /// <summary>
    /// 筛选表单配置模型
    /// </summary>
    public class AJTableSearchFormConfig : BindableBase
    {
        private bool _isExport;
        /// <summary>
        /// 是否是导出标志， 由表格组件赋值， 其他任何时候不建议直接复制
        /// </summary>
        public bool IsExport
        {
            get
            {
                return _isExport;
            }
            set
            {
                _isExport = value;
            }
        }

        private Visibility _exportVisibility = Visibility.Collapsed;

        public Visibility ExportVisibility
        {
            get { return _exportVisibility; }
            set
            {
                SetProperty(ref _exportVisibility, value);
            }
        }

        private Visibility _advFilterVisibility = Visibility.Visible;

        public Visibility AdvFilterVisibility
        {
            get { return _advFilterVisibility; }
            set
            {
                SetProperty(ref _advFilterVisibility, value);
            }
        }

        private Visibility _settingVisibility = Visibility.Visible;

        public Visibility SettingFilterVisibility
        {
            get { return _settingVisibility; }
            set
            {
                SetProperty(ref _settingVisibility, value);
            }
        }

        private ObservableCollection<AJTableSearchFormSchema> _schemas;

        /// <summary>
        /// 表单项目列表
        /// </summary>
        public ObservableCollection<AJTableSearchFormSchema> Schemas
        {
            get { return _schemas; }
            set
            {
                SetProperty(ref _schemas, value);
            }
        }

        public List<AJTableSearchFormSchema> PopularSchemas
        {
            get
            {
                return _schemas.Where(p => p.IsPopular).ToList();
            }
        }

        private static readonly AJTableSearchFormConfig _default = new AJTableSearchFormConfig
        {
            SettingFilterVisibility = Visibility.Visible,
            AdvFilterVisibility = Visibility.Collapsed,
            ExportVisibility = Visibility.Collapsed,
            Schemas = new ObservableCollection<AJTableSearchFormSchema>()
        };

        public static AJTableSearchFormConfig Default
        {
            get { return _default; }
        }

        public void Reset()
        {
            foreach (var item in Schemas)
            {
                switch (item.Type)
                {
                    case AJTableSchemaType.Input:
                    case AJTableSchemaType.Select:
                    case AJTableSchemaType.DateTimePicker:
                    case AJTableSchemaType.CheckBox:
                    case AJTableSchemaType.RadioBox:
                    case AJTableSchemaType.Switch:
                        item.Value = null;
                        break;
                    case AJTableSchemaType.MultiSelect:
                        item.Value = new ObservableCollection<AJTableFormSchemaItemOptions>();
                        break;
                    case AJTableSchemaType.RangePicker:
                        item.Value = new ObservableCollection<DateTime?>(new DateTime?[] { null, null });
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
